﻿@model ATTools.ViewModels.SoundPartViewModel
@using Orchard.Utility.Extensions;
@using ATTools.Helpers;

@{
	Script.Require("jQuery").AtFoot();
	Script.Require("AudioPlayer").AtFoot();

	string displaySound = "inline";

	if (string.IsNullOrWhiteSpace(Model.Part.SoundString))
	{
		displaySound = "none";
	}

	string displayCustom = "inline";

	if (string.IsNullOrWhiteSpace(Model.Part.CustomSoundString))
	{
		displayCustom = "none";
	}
}

<fieldset>
  
  <div class="editor-label">
	@T("Sound of bodytext")
  </div>

  @if (@Model.Part.SoundString == null)
  {
	  <p>@T("An autogenerated sound of the bodytext will be generated when you click the \"Publish Now\" button")</p> 
  }

  <div style="display: @displaySound" id="soundStringPlayer" class="audioplayer">
	<audio src="@Model.Part.SoundString" class="audioElement" preload="none"></audio>
	<span class="soundControl">
		<span>@T("Sound player:")</span>
		<a href="#" class="play">@T("Play")</a>
		<a href="#" class="pause" style="display:none">@T("Pause")</a>
		<a href="#" class="stop" style="display:none">@T("Stop")</a>
	</span>
    <a class="soundLink" href="@Model.Part.SoundString">(@T("Download"))</a>
	<br />
  </div>

  <br />



  <div>
		<label for="SiteSettings_VoiceName">@T("Language of sound")</label>
		@Html.DropDownList("LanguageOfSound", new SelectList(Model.AvailableLanguages, "Name", "FriendlyName", Model.Part.LanguageOfSound))
		@Html.ValidationMessage("LanguageOfSound", "*")
  </div>
  
  <br />

  <div>
		@Html.EditorFor(m => m.UseCustomSound) 
		<label class="forcheckbox" for="@Html.FieldIdFor(m => m.UseCustomSound)">@T("Use a custom sound")</label>
		@Html.ValidationMessage("UseCustomSound", "*")
  </div>

  <div class="editor-field" data-controllerid="@Html.FieldIdFor(m => m.UseCustomSound)">
	<input id="SoundUploadField" name="SoundUploadField" type="file" value="@T("Browse") size="64" />
	<div style="display: @displayCustom" id="customSoundStringPlayer" class="audioplayer">
	<audio src="@Model.Part.CustomSoundString" class="audioElement" preload="none"></audio>
	<span class="soundControl">
		<span>@T("Sound player:")</span>
		<a href="#" class="play">@T("Play")</a>
		<a href="#" class="pause" style="display:none">@T("Pause")</a>
		<a href="#" class="stop" style="display:none">@T("Stop")</a>
	</span>
    <a class="soundLink" href="@Model.Part.CustomSoundString">(@T("Download"))</a>
	</div>
  </div>

  

			
</fieldset>

@using(Script.Foot()) {
<script type="text/javascript">
	(function ($) {
		$(document).ready(function () {

			$('form')
				.attr('enctype', 'multipart/form-data')
				.attr('encoding', 'multipart/form-data');

			$('#soundStringPlayer').audioPlayer({
				audioUrl: '@Model.Part.SoundString',
				playType: '@Html.Raw(AudioSupportHelper.GetPlayType(Model.Part.SoundString))'
			});

			$('#customSoundStringPlayer').audioPlayer({
				audioUrl: '@Model.Part.CustomSoundString',
				playType: '@Html.Raw(AudioSupportHelper.GetPlayType(Model.Part.CustomSoundString))'
			});
		});

	})(jQuery);
</script>
}